package dao;

import java.util.LinkedList;
import java.util.List;

import relations.Associate;
import relations.belongsTo;
import relations.contains;
import entities.Media_Company;
import entities.Product;
import entities.album;
import entities.order;
import entities.User;

public class containsDAO {

	private static final containsDAO instance = new containsDAO();
	//private List<Product> containsProduct;
	//private List<order> containsOrder;
	private List<contains> containsList;
	
	private containsDAO(){
		//containsProduct = new LinkedList<Product>();
		//containsOrder = new LinkedList<order>();
		containsList = new LinkedList<contains>();
		contains cus = null;
		
		//cus = Associate.newInstance("jaime", "Jaime", "Vazquez", "ja@j.com", 1L, "test", "kl", "1", "00778", "PR", "Gurabo", "USA");
		//belongsTos.add(cus);
		//cus = belongsTo.newInstance("jaime1", "Jaime", "Vazquez", "ja@j.com", 2L, "test", "kl", "1", "00778", "PR", "Gurabo", "USA");
		//belongsTos.add(cus);
	}
	
	public static containsDAO getInstance() {
		return instance;
	}

	public synchronized contains findContains(Long product_id, String orderID, float price, int qty) {
		contains result = null;
		
		for (contains s : containsList){
			if (s.getProduct_id().equals(product_id) && s.getOrderID().equals(orderID) && s.getPrice() == price && s.getQty() == qty ){
				result = s;
				
			}
		}
		
	
			//result = new Associate(result1.getProduct_id(), result2.getName());
	
		return result;
	}

	public synchronized void addContains(contains obj) throws RecordDuplicateException{
		if (findContains(obj.getProduct_id(), obj.getOrderID(), obj.getPrice(), obj.getQty() ) != null){
			throw new RecordDuplicateException("Relation Contains with Product ID: " + obj.getProduct_id() + " and" + " Order ID: " + obj.getOrderID() + " is already in the db.");
		}
		else {
			containsList.add(obj);
			
		}
	}

}
